using System.Drawing;
using System.Windows.Forms;
using DrawTools.Editor.CanvasFigures;

namespace DrawTools.Editor.Tools.States
{
  internal class NetSelectionState : IPointerToolState
  {
    private readonly IDrawingCanvas _canvas;
    private readonly Point _startPoint;

    public NetSelectionState(IDrawingCanvas canvas, Point startPoint)
    {
      _canvas = canvas;
      _startPoint = startPoint;

      // click on background
      if ((Control.ModifierKeys & Keys.Control) == 0)
        _canvas.GraphicsList.DeselectAll();

      _canvas.NetRectangle = CanvasRectangleBase.GetNormalizedRectangle(_startPoint, _startPoint);
      _canvas.IsDrawNetRectangle = true;
    }

    #region IPointerToolState Members

    public void Update(Point point)
    {
      _canvas.NetRectangle = CanvasRectangleBase.GetNormalizedRectangle(_startPoint, point);
      _canvas.Refresh();
    }

    public void Release()
    {
      // Group selection
      _canvas.GraphicsList.SelectInRectangle(_canvas.NetRectangle);

      //_selectMode = SelectionMode.None;
      _canvas.IsDrawNetRectangle = false;
    }

    #endregion
  }
}